<template>
  <div class="operate-button-container">
    <el-row>
      <el-col :span="3">
        <el-button
          size="small"
          round
          type="primary"
          plain
          icon="el-icon-plus"
          @click="handleCreate"
        >新增</el-button>
      </el-col>
      <el-col :span="3">
        <el-button size="small" round type="info" plain icon="el-icon-edit" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="3">
        <el-button
          size="small"
          round
          type="danger"
          plain
          icon="el-icon-delete"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'OperateButton',
  props: {
    multipleSelection: Array
  },
  methods: {
    handleCreate() {
      this.$router.push({ path: '/system/entity/entityInfo' })
    },
    handleEdit() {
      if (this.multipleSelection.length == 1) {
        var dataId = this.multipleSelection[0].id
        this.$router.push({ path: '/system/entity/entityInfo', query: { id: dataId } })
      } else {
        this.$message.error('请勾选一条记录进行修改！')
      }
    },
    handleDelete() {
      if (this.multipleSelection.length == 1) {
        this.$confirm('是否删除此记录?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            var dataId = this.multipleSelection[0].id
            this.$store.dispatch('entity/deleteData', dataId).then(() => {
              this.$emit('handleSearch')
            })
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
      } else {
        this.$message.error('最多只能删除一条记录')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>